//
//  Marker.h
//  newAR
//
//  Created by ZJU_CVG on 15/1/29.
//  Copyright (c) 2015年 Shangjin Zhai. All rights reserved.
//

#ifndef newAR_Marker_h
#define newAR_Marker_h

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include "Basic Structure.h"
#include "ORB.h"
#include "keyframe.h"
#include "ImageWarp.hpp"
#include "LA.hpp"
using namespace std;


#define PyramidSize 5

namespace markerAR
{
    
class Marker
{
public:
	Marker();
	~Marker();
    Marker(const Mat&img, const Eigen::Matrix3d& R, int id,const double scale = 0.25, int levelNum = 8, float scaleFactor_ = 1.25);
	SingleScaleStructrue* orbStructure;
    MultiScaleStructure* multiBrief;
	Pose C;

	void reset();
	bool registed;
    int id()const{return _id;}
	cv::Mat img;
    
    std::shared_ptr<Keyframe> keyframe;
    Marker* markerNow;
    
	cv::Point3f center;
    inline const CoeffBlock& getCoeffBlock(int i,int j)const{return Coeffs[i][j];}
    void warpTo(const Eigen::Matrix3d &Hnm,const cv::Mat &mask,cv::Mat &warpImg)const;
    Eigen::Matrix3d warpScale(const Eigen::Matrix3d &H,const cv::Mat&mask,cv::Mat&warpImg,int level)const;
    Marker(const Marker&) = delete;
    Marker operator=(const Marker&) = delete;
    std::mutex m;
    
private:
    CoeffBlock** Coeffs;//coefficent for bilinear interpolation
	void buildImages(const Mat& img);
	void solve3d(const Mat &R);
    Eigen::Matrix3d scaleK;
    int _id;
    float scaleFactor;
};


}




#endif
